﻿<script src="https://cdnjs.cloudflare.com/ajax/libs/monaco-editor/0.48.0/min/vs/loader.min.js" 
        integrity="sha512-ZG31AN9z/CQD1YDDAK4RUAvogwbJHv6bHrumrnMLzdCrVu4HeAqrUX7Jsal/cbUwXGfaMUNmQU04tQ8XXl5Znw==" 
        crossorigin="anonymous" 
        referrerpolicy="no-referrer"></script>
<script>
    require.config({ paths: { 'vs': 'https://cdnjs.cloudflare.com/ajax/libs/monaco-editor/0.48.0/min/vs' } });

    function initEditor(containerId, textAreaQuerySelector, lang) {
        var editorDiv = document.getElementById(containerId);
        var editorInstance = monaco.editor.create(editorDiv, {
            language: lang
        });
        editorInstance.layout();

        var editorValue = document.querySelector(textAreaQuerySelector).value;
        editorInstance.setValue(editorValue);

        return editorInstance;
    }

    function insertTextToMonacoEditor(editor, text) {
        var selection = editor.getSelection();
        var range = new monaco.Range(selection.startLineNumber, selection.startColumn, selection.endLineNumber, selection.endColumn);
        editor.executeEdits("", [{
            range: range,
            text: text,
            forceMoveMarkers: true
        }]);
    }

    var assignEditorValues = function (editor, textAreaQuerySelector) {
        var editorValue = editor.getValue();
        document.querySelector(textAreaQuerySelector).value = editorValue;
    }
</script>